package com.cheer.controller;

import com.cheer.security.UserInfoHolder;
import com.cheer.service.StandingBookDocumentService;
import com.cheer.vo.DocumentMemberVO;
import com.cheer.vo.DocumentVO;
import com.cheer.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/document")
public class DocumentController {

    @Autowired
    private StandingBookDocumentService standingBookDocumentService;

    @Autowired
    private UserInfoHolder userInfoHolder;

    /**
     * 下载文档模板
     */
    @GetMapping("/template")
    public Result<String> getTemplate(@RequestParam Integer type) {
        String docUrl = standingBookDocumentService.getTemplateByType(type);
        return Result.success(docUrl);
    }

    /**
     * 上传成员信息文档
     */
    @PostMapping("/member/upload")
    public Result<DocumentMemberVO> uploadMember(MultipartFile file) {
        DocumentMemberVO documentMemberVO = standingBookDocumentService.uploadMemberDocument(userInfoHolder.getAccountId(), file);
        return Result.success(documentMemberVO);
    }

    /**
     * 上传文档
     */
    @PostMapping("/upload")
    public Result<DocumentVO> upload(MultipartFile file) {
        DocumentVO documentVO = standingBookDocumentService.upload(userInfoHolder.getAccountId(), file);
        return Result.success(documentVO);
    }

}
